package com.jrew.gae.wcs.spring.controllers;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

import com.jrew.gae.wcs.constants.AppConstant;
import com.jrew.gae.wcs.entities.PlayerStats;
import com.jrew.gae.wcs.spring.services.StatsManagerService;

/**
 *
 */
public class GetLevelStatsController extends AbstractController {
		
	private StatsManagerService statsManagerService;
	private int playersNumber;
	private String viewName;
	private String modelName;
	
	@Override
	protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
		
		String levelStr = request.getParameter(AppConstant.LEVEL);
		int level = Integer.parseInt(levelStr);
		String locale = request.getParameter(AppConstant.LOCALE);
		
		List<PlayerStats> stats = statsManagerService.getStats(level, locale, playersNumber);
		return new ModelAndView(viewName, modelName, stats);
	}

	/**
	 * @return
	 */
	public StatsManagerService getStatsManagerService() {
		return statsManagerService;
	}

	/**
	 * @param statsManagerService
	 */
	public void setStatsManagerService(StatsManagerService statsManagerService) {
		this.statsManagerService = statsManagerService;
	}

	/**
	 * @return
	 */
	public int getPlayersNumber() {
		return playersNumber;
	}

	/**
	 * @param playersNumber
	 */
	public void setPlayersNumber(int playersNumber) {
		this.playersNumber = playersNumber;
	}

	/**
	 * @return
	 */
	public String getViewName() {
		return viewName;
	}

	/**
	 * @param viewName
	 */
	public void setViewName(String viewName) {
		this.viewName = viewName;
	}

	/**
	 * @return
	 */
	public String getModelName() {
		return modelName;
	}

	/**
	 * @param modelName
	 */
	public void setModelName(String modelName) {
		this.modelName = modelName;
	}
}
